package com.wclass.controller.app;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.wclass.common.ReturnObject;
import com.wclass.entity.BaseRecruitment;
import com.wclass.entity.BaseRecruitmentType;
import com.wclass.entity.CourseType;
import com.wclass.interceptor.IgnoreAuth;
import com.wclass.service.IBaseRecruitmentService;
import com.wclass.service.IBaseRecruitmentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 人才招聘 前端控制器
 * </p>
 *
 * @author SEN
 * @since 2019-02-13
 */
@Api(description = "人才招聘管理")
@RestController
@RequestMapping("/recruitment")
public class RecruitmentController {

    @Autowired
    private IBaseRecruitmentTypeService recruitmentTypeService;
    @Autowired
    private IBaseRecruitmentService recruitmentService;

    @IgnoreAuth
    @ApiOperation("获取招聘分类和分类职位数量")
    @RequestMapping(value = "/getRecruitmenTypeList", method = RequestMethod.POST)
    public ReturnObject<List<BaseRecruitmentType>> getRecruitmenTypeList() {
        List<BaseRecruitmentType> list = recruitmentTypeService.findCountList();
        return new ReturnObject<>(0, "获取成功", list);
    }

    @IgnoreAuth
    @ApiOperation("获取招聘分页")
    @RequestMapping(value = "/getRecruitmenPage", method = RequestMethod.POST)
    public ReturnObject<List<Map<String, Object>>> getRecruitmenPage(@ApiParam("每页条数") @RequestParam(defaultValue = "10") Integer limit,
                                                                     @ApiParam("页数") @RequestParam(defaultValue = "1") Integer offset,
                                                                     @ApiParam("分类id") Long typeId) {
        EntityWrapper ew = new EntityWrapper<BaseRecruitment>();
        if (typeId != null && typeId != 0) {
            ew.eq("type_id", typeId);
        }
        Page<BaseRecruitment> obj = recruitmentService.selectPage(new Page<>(offset, limit), ew);

        List<Map<String, Object>> list = Lists.newArrayList();
        for (BaseRecruitment info : obj.getRecords()) {
            Map<String, Object> map = Maps.newHashMap();
            map.put("id", info.getId());
            map.put("title", info.getTitle());
            map.put("place", info.getPlace());
            map.put("education", info.getEducation());
            map.put("salary", info.getSalary());
            map.put("workYear", info.getClaimWorking());
            map.put("time", info.getCrtTime());
            list.add(map);
        }
        return new ReturnObject<>(0, "获取成功", obj.getTotal(), obj.getPages(), list);
    }

    @IgnoreAuth
    @ApiOperation("获取招聘详情信息")
    @RequestMapping(value = "/getRecruitmenInfoById", method = RequestMethod.POST)
    public ReturnObject<BaseRecruitment> getRecruitmenInfoById(@ApiParam("id") Long id) {
        return new ReturnObject<>(0, "获取成功", recruitmentService.selectById(id));
    }

}

